<template>
  <div class="transac">
    <div class="bg-c-fff">
      <h2 class="right-title rel">交易监控订单</h2>
      <a @click.stop="onJump()" class="small-btn-css btn rel">发起新交易</a>
      <div class="right-box">
        <choose-type typename="订单状态" valuename="orderType" :itemlist="orderlist" :active="orderActive" @typechanged="onOptionChanged"></choose-type>
        <choose-type typename="交易阶段" valuename="transType" :itemlist="translist" :active="transActive" @typechanged="onOptionChanged"></choose-type>
        <choose-type typename="监控类型" valuename="monitorType" :itemlist="monitorlist" :active="monitorActive" @typechanged="onOptionChanged"></choose-type>
        <table>
          <tr>
            <th>时间</th>
            <th>订单编号</th>
            <th>发起人</th>
            <th>监控类型</th>
            <th>交易阶段</th>
            <th>订单状态</th>
            <th>操作</th>
          </tr>
          <tr v-for="item in transacList">
            <td>{{item.createTime}}</td>
            <td>{{item.id}}</td>
            <td>{{item.businessName}}</td>
            <td>{{item.monitorType | monitorFilter}}</td>
            <td>{{item.status | statusFilter}}</td>
            <td>{{item.stage | stageFilter}}</td>
            <td><a class="auto small-btn-css" @click="onItemClick(item)">查看详情</a></td>
          </tr>
        </table>
        <div class="no-data-tip" v-show="transacList.length===0">暂无相关数据</div>
        <pagination :index="pageIndex" :total="pageTotal" v-show="this.transacList!=0" @pagechange="onPageChange"></pagination>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
import Calendar from '../components/Calendar'
import Pagination from '../components/Pagination'
import ChooseType from '../components/ChooseType'
export default {
  components: {
    Pagination,
    Calendar,
    ChooseType
  },
  data() {
    return {
      pageIndex: 1,
      pageTotal: 0,
      name: '',
      orderActive: '',
      transacList: [],
      orderlist: [{
        value: '',
        text: '全部'
      }, {
        value: '1',
        text: '进行中'
      }, {
        value: '2',
        text: '已完成'
      }, {
        value: '3',
        text: '已终止'
      }],
      transActive: '',
      translist: [{
        value: '',
        text: '全部'
      }, {
        value: '1',
        text: '提交服务申请'
      }, {
        value: '2',
        text: '确认资质报告'
      }, {
        value: '3',
        text: '合同审查'
      }, {
        value: '4',
        text: '绘制流程图'
      }, {
        value: '5',
        text: '交易监控'
      }, {
        value: '6',
        text: '服务评价'
      }, {
        value: '7',
        text: '完成评价'
      }],
      monitorActive: '',
      monitorlist: [{
        value: '',
        text: '全部'
      }, {
        value: '1',
        text: '单方监控'
      }, {
        value: '2',
        text: '双方监控'
      }, {
        value: '3',
        text: '多方监控'
      }]
    }
  },
  mounted() {
    this.onPageChange(1)
    this.name = this.$store.state.userInfo.account
  },
  methods: {
    onPageChange(n) {
      this.getTransacData(n)
    },
    onOptionChanged(type, value) {
      if (type === 'orderType') {
        this.orderActive = value
      }
      if (type === 'transType') {
        this.transActive = value
      }
      if (type === 'monitorType') {
        this.monitorActive = value
      }
      this.getTransacData(1)
    },
    getTransacData(n) {
      var parms = {
        pageIndex: n,
        pageTotal: 0,
        status: this.transActive,
        stage: this.orderActive,
        monitorType: this.monitorActive
      }
      this.$http.get('/transactionMonitorSer/business/read/list', {
        params: parms
      }).then(data => {
        if (data.data.httpCode === 200) {
          this.pageIndex = n
          this.pageTotal = Math.ceil(data.data.total / 10)
          this.transacList = data.data.rows
        } else {
          console.log(data.data.msg)
          this.$toasted.show(data.data.msg)
        }
      }).catch(err => {
        console.log(err)
      })
    },
    onItemClick(item) {
      if (item.modify === 1) {
        this.$toasted.show('正在纠错中，请稍后查看')
      } else {
        if (item.status === 1) {
          this.$router.push('/submit-apply?id=' + item.id)
        }
        if (item.status === 2) {
          this.$router.push('/confirm-aptitude?id=' + item.id)
        }
        if (item.status === 3) {
          this.$router.push('/contract-review?id=' + item.id)
        }
        if (item.status === 4) {
          this.$router.push('/transac-service-wait?id=' + item.id)
        }
        if (item.status === 5) {
          this.$router.push('/transactionsurveillance?id=' + item.id)
        }
        if (item.status >= 6) {
          this.$router.push('/service-evalua?id=' + item.id)
        }
      }
    },
    onJump() {
      this.$router.push('/submit-apply')
    }
  },
  filters: {
    monitorFilter(v) {
      if (v === 1) {
        return '单方监控'
      }
      if (v === 2) {
        return '双方监控'
      }
      if (v === 3) {
        return '多方监控'
      }
    },
    statusFilter(v) {
      if (v === 1) {
        return '提交服务申请'
      }
      if (v === 2) {
        return '确认资质报告'
      }
      if (v === 3) {
        return '合同审查'
      }
      if (v === 4) {
        return '绘制流程图'
      }
      if (v === 5) {
        return '交易监控'
      }
      if (v === 6) {
        return '服务评价'
      }
      if (v === 7) {
        return '完成评价'
      }
    },
    stageFilter(v) {
      if (v === 1) {
        return '进行中'
      }
      if (v === 2) {
        return '已完成'
      }
      if (v === 3) {
        return '已终止'
      }
    }
  }
}

</script>
<style type="text/css" scoped>
.rel {
  border-bottom: 2px solid #f5f5f5
}

.right-box {
  padding: 40px 30px;
  color: #666666;
  line-height: 30px;
  margin-bottom: 20px;
}

a {
  cursor: pointer
}

table {
  margin-top: 20px;
}

table th,
table td {
  width: 132px;
}

table td {
  line-height: normal;
}

table td a {
  display: block;
  background-color: #3881f2;
  color: #fff;
}

.btn {
  background-color: #01378c;
  color: #fff;
  float: right;
  text-align: center;
  margin-right: 30px;
  margin-top: -36px;
}

</style>
